package homework;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class ArrayStuTest {
    public static void main(String[] args) {
        //定义集合
        List<Student> list = new ArrayList<>();
        //键盘输入
        Scanner sc = new Scanner(System.in);
        //定义判断
        boolean flag = true;
        while (flag){
            System.out.println("选择（1.录入；0退出）");
            int choice = sc.nextInt();
            //对选择判断
            if (choice == 1){
                System.out.println("姓名：");
                String name = sc.next();//键盘输入姓名

                System.out.println("年龄：");
                int age = sc.nextInt();//键盘输入年龄

                list.add(new Student(name,age));
            }
            else if (choice == 0){
                flag = false;
            }
        }
        for (Student student : list) {
            System.out.println(student);
        }
    }
}
class Student{
    private String name;
    private int age;
    public Student(){}
    public Student(String name,int age){
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}